//T10080. 二叉树输出
#include <iostream>
using namespace std;
struct node;
typedef node* bt;
struct node {
    char data;
    int len;
    bt lchild=nullptr;
    bt rchild=nullptr;
};
string s1,s2;
bt build_tree(int l1,int r1,int l2,int r2){
    bt root=new node;
    root->data=s1[l1];
    root->len=0;
    if (l1<r1){
        int m=s2.find(s1[l1]);
        if (m>l2) {
            root->lchild=build_tree(l1+1,m+l1-l2,l2,m-1);
            root->len+=root->lchild->len;
        }
        if (m<r2) {
            root->rchild=build_tree(m+1+r1-r2,r1,m+1,r2);
            root->len+=root->rchild->len;
        }
    }else root->len=1;
    return root;
}
void out_tree(bt root){
    if (root){
        for(int k=1;k<=root->len;k++) cout<<root->data;
        cout<<endl;
        out_tree(root->lchild);
        out_tree(root->rchild);
    }
}   
int main(){
    cin>>s1>>s2;
    bt r=build_tree(0,s1.length()-1,0,s2.length()-1);
    out_tree(r);
}